<?php

namespace App\Modules\Admin\Repositories\Impl;

use App\Modules\Admin\Models\AdminUser;
use App\Modules\Admin\Repositories\Contracts\AdminUserRepository;
use App\Modules\Admin\Repositories\Transformers\AdminUserTransformer;

class AdminUserRepositoryImpl implements AdminUserRepository
{
    public function paginate($perPage, $filter)
    {
        $adminUsers = AdminUser::paginate($perPage);
        $result = fractal($adminUsers, new AdminUserTransformer());

        return $result->toArray();
    }

    public function find($id, $columns = ['*'])
    {
        return AdminUser::find($id, $columns);
    }

    public function findByFilter($filter, $columns = ['*'])
    {
        return AdminUser::where($filter)->first($columns);
    }

    public function store($data)
    {
        return AdminUser::create($data);
    }

    public function update($data, $id)
    {
        return AdminUser::whereId($id)->updateOrCreate($data);
    }
    public function updateByFilter($data, $where)
    {
        return AdminUser::where($where)->update($data);
    }

    public function delete($id)
    {
        return AdminUser::whereId($id)->delete();
    }
}
